var $ = jQuery.noConflict();
// cufon
//Cufon.replace('h1, h2, h3, h4, h5, h6, label');
$(document).ready(function() {
	// categories menu
	$(".mainMenu > li").hover(function() {
		$(this).find("> ul").stop(true, true).animate({
			height: "show"
		}, 200, "easeOutCubic");
	}, function() {
		$(this).find("> ul").stop(true, true).animate({
			height: "hide"
		}, 200, "easeOutCubic");
	});
	$(".mainMenu > li").each(function() {
		if ($(this).find("ul").length > 0) {
			$(this).addClass("hasSubMenu");
		}
	});
	// login
	$(".loginBtn").hover(function() {
		$(this).find(".loginFormWrap").stop(true, true).animate({
			height: "show"
		}, 300, "easeOutCubic");
	}, function() {
		$(this).find(".loginFormWrap").stop(true, true).animate({
			height: "hide"
		}, 300, "easeOutCubic");
	});
	// animate linked images
	$("a").hover(function() {
		$(this).find("> img").stop(true, true).animate({
			opacity: 0.7
		}, 300, "easeOutCubic");
	}, function() {
		$(this).find("> img").stop(true, true).animate({
			opacity: 1
		}, 300, "easeOutCubic");
	});
	// sort 
	$("#orderList").click(function() {
		$(".postImage").css({
			"display": "none"
		});
		$(".attachLinks").css({
			"display": "none"
		});
		$("#orderFull").css({
			"background-position": "0px -20px"
		});
		$(this).css({
			"background-position": "-28px -20px"
		});
		$(".postLargeInfo").css({
			"width": "582px"
		});
		$(".postSmallInfo").css({
			"width": "582px"
		});
		return false;
	});
	$("#orderFull").click(function() {
		$(".postImage").css({
			"display": "block"
		});
		$(".attachLinks").css({
			"display": "block"
		});
		$(this).css({
			"background-position": "0px 0px"
		});
		$("#orderList").css({
			"background-position": "-28px 0px"
		});
		$(".postLargeInfo").css({
			"width": "317px"
		});
		$(".postSmallInfo").css({
			"width": "452px"
		});
		return false;
	});
	// slider hide list
	$("#openList").click(function() {
		$(".moreSlides").stop().animate({
			height: "show"
		}, 300, "easeOutCubic");
		return false;
	});
	$("#closeList").click(function() {
		$(".moreSlides").stop().animate({
			height: "hide"
		}, 300, "easeOutCubic");
		return false;
	});
	//jquery tabs	
	$("ul.footerTabs").tabs("div.footerTabsWrap > div", {
		effect: 'fade',
		fadeSpeed: 300,
		initialIndex: 0,
		history: "false"
	});
	$("ul.tabsMenu").tabs("div.homeTabs > div", {
		effect: 'fade',
		fadeSpeed: 300,
		initialIndex: 0,
		history: "false"
	});
	$("ul.userTabsMenu").tabs("div.userPersonalInfo > div", {
		effect: 'fade',
		fadeSpeed: 300,
		initialIndex: 0,
		history: "false"
	});
	// cycle plugin
	$('.slidesWrap').cycle({
		fx: 'scrollLeft',
		// effect
		easing: 'linear',
		// set the easing you want , easeInElastic, easeOutBack  ...
		speed: 700,
		// speed of transition
		timeout: 3200,
		// timeout of the slide
		pause: false,
		// true to enable "pause on hover"
		pauseOnPagerHover: false,
		// true to pause when hovering over pager link
		//pager:  '#sliderNavList',
		next: '#nextSlide',
		prev: '#prevSlide',
		cleartypeNoBg: true,
		// fix cleartype inside slides
		cleartype: true // fix cleartype inside slides
	});
	// side share
	var msie6 = $.browser == 'msie' && $.browser.version < 7;
	if (!msie6 && $('#share_buttons_single_page').length != 0) {
		var top = $('#share_buttons_single_page').offset().top - parseFloat($('#share_buttons_single_page').css('margin-top').replace(/auto/, 0));
		$(window).scroll(function(event) {
			// what the y position of the scroll is
			var y = $(this).scrollTop();
			// whether that's below the form
			if (y >= top - 20) {
				// if so, ad the fixed class
				$('#share_buttons_single_page').addClass('fixed');
			} else {
				// otherwise remove it
				$('#share_buttons_single_page').removeClass('fixed');
			}
		});
	}
	// side ad starts
	// side share
	// if (!msie6 && $('#sideAdLargeRight').length != 0) {
	// var topAd = $('#sideAdLargeRight').offset().top - parseFloat($('#sideAdLargeRight').css('margin-top').replace(/auto/, 0));
	// $(window).scroll(function (event) {
	// what the y position of the scroll is
	// var yAd = $(this).scrollTop();
	// whether that's below the form
	// if (yAd >= topAd-20) {
	// if so, ad the fixed class
	// $('#sideAdLargeRight').addClass('fixed');
	// } else {
	// otherwise remove it
	// $('#sideAdLargeRight').removeClass('fixed');
	// }
	// });
	// }
	// side ad ends
	// header fixed starts
	if (!msie6) {
		var topHeader = $('.headerWrap').height();
		$(window).scroll(function(event) {
			// what the y position of the scroll is
			var yHeader = $(this).scrollTop();
			// whether that's below the form
			if (yHeader >= topHeader) {
				// if so, ad the fixed class
				$('.headerWrap').addClass('headerWrapFixed');
				$('.pageWrap').css({
					"margin-top": "195px"
				});
			} else {
				// otherwise remove it
				$('.headerWrap').removeClass('headerWrapFixed');
				$('.pageWrap').css({
					"margin-top": "15px"
				});
			}
		});
	}
	// header fixed ends
	// click events for loading forms begin here
	$('.load-form').click(function(e) {
		e.preventDefault();
		var mask = $('<div></div>');
		var holder = $('<div></div>');
		$('body').append(mask);
		$('body').append(holder);
		mask.addClass('mask');
		Fill(mask);
		$(window).resize(function() {
			Fill(mask);
		});
		mask.click(function() {
			holder.effect("shake", {
				times: 1,
				distance: 5
			}, 50, function() {});
		});
		holder.addClass('holder');
		holder.hide();
		var form = $(this).attr('load');
		$.ajax({cache : false, 
			type: "GET",
			url: "/form_handler.php",
			data: 'form=' + form + '&-dt=' + document.title + '&-wl=' + window.location,
			success: function(response) {
				holder.html(response);
				Centre(holder);
				$(window).resize(function() {
					Centre(holder);
				});
				holder.show();
			}
		});
	});
	// click events for loading forms end here	 
}); //ducument ready ends

function Fill(element) {
	element.height($(window).height());
	element.width($(window).width());
}

function Centre(element) {
	element.css('left', (($(window).width() - element.outerWidth()) / 2) + 'px');
	element.css('top', (($(window).height() - element.outerHeight()) / 2) + 'px');
}
// google plus
(function() {
	var po = document.createElement('script');
	po.type = 'text/javascript';
	po.async = true;
	po.src = 'https://apis.google.com/js/plusone.js';
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(po, s);
})();
// facebook like
// (function(d, s, id) {
	// var js, fjs = d.getElementsByTagName(s)[0];
	// if (d.getElementById(id)) {
		// return;
	// }
	// js = d.createElement(s);
	// js.id = id;
	// js.src = "//connect.facebook.net/en_US/all.js#appId=253463821359760&xfbml=1";
	// fjs.parentNode.insertBefore(js, fjs);
// }(document, 'script', 'facebook-jssdk'));
// Lankasri FM Player in POP UP
$(document).ready(function() {
	$('.openplayer').click(function() {
		window.open($('.openplayer').attr('href'), "mywindow", "status=1,width=770,height=474,resizable=0");
		return (false);
	});
});